<template>
	<div v-loading="tableLoad">
		<BaseContainer
		class="report-table-wrapper"
		v-loading="loading"
		element-loading-text="加载中..."
		element-loading-background="rgba(255, 255, 255, 0.8)"
	>
		<div class="t-header">
			<div class="article-title">
				<span>浦口区政府养老扶助对象入住养老机构补助核准表</span>
			</div>
		</div>
		<ReportTable
			:column="dataList"
			:isDetail="true"
			:moreNewsModel="moreNewsModel"
			:baseModel="baseModel"
			:model="modelData"
			@change="handleSave"
		>
			<template v-slot:areaOpinion>
				<div style="text-align: left">
					<p class="fr_sta">机构所在区意见：
						<span>
							<el-input v-if="!editMode.orgCrArea&&!hideInput&&isOkApproval" class="input_part" v-model="modelData.orgCrAreaOpinion" @blur="saveEditData" type="text" />
							<span v-else>
								<span class="add_underline" v-if="modelData.orgCrAreaOpinion">{{ modelData.orgCrAreaOpinion }}</span>
								<span v-else></span>
							</span>
						</span>
					</p>
					<p style="margin-bottom: 5vh">请移交民政部门办理。</p>
					<p>区民政部门（盖章）</p>
				</div>
			</template>
			<template v-slot:crAreaOpinion>
				<div style="text-align: left">
					<p class="fr_sta">老年人户籍所在区意见：
						<span>
							<el-input v-if="!editMode.elderCrArea&&!hideInput&&isOkApproval" class="input_part" v-model="modelData.elderCrAreaOpinion" @blur="saveEditData" type="text" />
							<span v-else>
								<span class="add_underline" v-if="modelData.elderCrAreaOpinion">{{ modelData.elderCrAreaOpinion }}</span>
								<span v-else></span>
							</span>
						</span>
					</p>
					<p style="margin-bottom: 5vh">请移交街道（镇）办理。</p>
					<p>区民政部门（盖章）</p>
				</div>
			</template>
			<template v-slot:TrialOutcome>
				<div style="text-align: left">
					<p>经核实，申请人（姓名）<span class="add_underline">{{modelData.oldmanName}}</span>:</p>
					<p style="text-indent: 2rem">1.有关材料反映情况 
						<CheckSelect v-model="modelData.reflectSituation" :isDetail="!editMode.streetAudit||!isOkApproval" :dictData="dict1" @change="saveEditData"></CheckSelect>
						,具体情况是:
							<el-input v-if="editMode.streetAudit&&isOkApproval" class="input_part" v-model="modelData.reflectDetail" type="text" @blur="saveEditData" />
							<span v-else>
								<span class="add_underline" v-if="modelData.reflectDetail">{{ modelData.reflectDetail }}</span>
								<span v-else>____________</span>
							</span>
					</p>
					<p style="text-indent: 2rem">2.生活自理能力状况：
						<CheckSelect v-model="modelData.isSelfCare" :isDetail="!editMode.streetAudit||!isOkApproval" :dictData="dict2" @change="saveEditData"></CheckSelect>
					</p>
					<div class="left_right">
						<span>经办人： （盖章）</span>
						<span>年 月 日</span>
					</div>
				</div>
			</template>
			<template v-slot:assessOutcome>
				<div style="text-align: left">
					<p>经评估，申请人（姓名）<span class="add_underline">{{modelData.oldmanName}}</span>生活自理能力等级为：</p>
					<p>
						<CheckSelect v-model="modelData.assessAbilityLevel" :isDetail="!editMode.assessOrgAudit||!isOkApproval" :dictData="dict3" @change="editAllData"></CheckSelect>
					</p>
					<div class="left_right">
						<span>评估人： （盖章）</span>
						<span>年 月 日</span>
					</div>
				</div>
			</template>
            <template v-slot:publicityOutcome>
				<div style="text-align: left">
					<p>
						<CheckSelect :isDetail="!editMode.societyAudit||!isOkApproval" v-model="modelData.objection" :dictData="dict4" :is-line="true" @change="saveEditData"></CheckSelect>
						<span v-if="modelData.objection==2">
							具体情况是:
							<el-input v-if="editMode.societyAudit&&isOkApproval" class="input_part" v-model="modelData.objectionDetail" @blur="saveEditData" type="text" />
							<span v-if="!editMode.societyAudit">
								<span v-if="modelData.objectionDetail" class="add_underline">{{ modelData.objectionDetail }}</span>
								<span v-else>____________</span>
							</span>
						
						</span>
					</p>
				</div>
			</template>
            <template v-slot:approvedOutcome>
				<div style="text-align: left">
					<p>经核查，申请人（姓名）<span class="add_underline">{{modelData.oldmanName}}</span>：</p>
					<p style="text-indent: 2rem;">1.符合南京市困难老人入住养老机构补助条件，从
						<span v-if="editMode.civilAudit&&isOkApproval">
							<el-date-picker
							v-model="modelData.startSubsidyDate"
							type="date"
							format="YYYY年MM月DD日"
							value-format="YYYY-MM-DD"
							placeholder="请选择日期"
							@change="editAllData"
							/>
						</span>
						<span v-else>
							<span v-if="modelData.startSubsidyDate">
								<span class="add_underline">{{ modelData.startSubsidyDate.split("-")[0] }}</span>年
								<span class="add_underline">{{ modelData.startSubsidyDate.split("-")[1] }}</span>月
								<span class="add_underline">{{ modelData.startSubsidyDate.split("-")[2] }}</span>日
							</span>
							<span v-else>__年__月__日</span>
						</span>
						
					起，入住养老机构期间享受补助。</p>
					<p style="text-indent: 2rem;">2.不符合南京市困难老人入住养老机构补助条件，理由是:<el-input v-if="editMode.civilAudit&&isOkApproval" class="input_part" v-model="modelData.dontCanAidReason" @blur="saveEditData" type="text" />
					<span v-else>
						<span v-if="modelData.dontCanAidReason" class="add_underline">{{ modelData.dontCanAidReason }}</span>
						<span v-else>___________</span>
					</span>
					</p>
                    <div class="left_right">
						<span>经办人： （盖章）</span>
						<span>年 月 日</span>
					</div>
				</div>
			</template>
            <template v-slot:remark>
				<div style="text-align: left">
					<p>
						停止享受补助时间：
						<span v-if="!modelData.stopAidDate">__年__月__日</span>
						<span v-if="modelData.stopAidDate">
							<span class="add_underline">{{ modelData.stopAidDate.split("-")[0] }}</span>年
							<span class="add_underline">{{ modelData.stopAidDate.split("-")[1] }}</span>月
							<span class="add_underline">{{ modelData.stopAidDate.split("-")[2] }}</span>日
						</span>
						，停止享受补助原因：</p>
					<p>
						<CheckSelect v-model="modelData.stopAidReason" :isDetail="true" :dictData="dict5" :is-line="true" @change="saveEditData"></CheckSelect>
						<!-- ,情况是:<span>
							<span v-if="modelData.stopAidOtherReason" class="add_underline">{{ modelData.stopAidOtherReason}}</span>
							<span v-else>________</span>
							
						</span> -->
					</p>
                    <p>经办人： （盖章） 年 月 日</p>
				</div>
			</template>
			<template v-slot:crDetail>
				{{modelData.crProvinceName}}{{ modelData.crCityName }}{{ modelData.crAreaName}}{{ modelData.crStreetName }}{{ modelData.crCommunityName }}{{ modelData.crAddress}}
			</template>
			<template v-slot:addressDetail>
				{{modelData.provinceName}}{{ modelData.cityName }}{{ modelData.areaName}}{{ modelData.streetName }}{{ modelData.communityName }}{{ modelData.address}}
			</template>
			<template v-slot:oldmanImage>
				<div v-if="!modelData.oldmanImage" style="width: 120px;"></div>
				<img v-else style="width: 120px;" :src="modelData.oldmanImage" alt="" srcset="">
			</template>
		</ReportTable>
        <div style="font-size: 14px;margin-bottom: 20px;">
            <span style="margin-right: 10vw;">所在区：{{ modelData.crAreaName }}</span>
            <span>街道（镇）：{{ modelData.crStreetName }}</span>
        </div>
        <div style="font-size: 14px;">填写说明：1.所有信息以填表时状态为准；2.经办人在符合实际情况&#9744;打“√”；3.本表格一式三份。街道（镇）民政办留存一份，区民政部门留存一份，养老机构留存一份。</div>
		<AplidDialog 
		v-model="archivalShow" 
		tilte="老人档案"
		whickComm="detail"
		:customeHeader="detailConfig?.customeHeader"
		:model="modelData"
		>
			<ElderArchives :showBtn="false" :nowRowData="modelData" :noOperation="true"></ElderArchives>
		</AplidDialog>
	</BaseContainer>
	</div>
	
</template>

<script setup lang="ts">
import ReportTable from '@/views/instOperate/components/ApplyReport/components/ReportTable/index.vue'
import ElderArchives from '@/views/instOperate/components/ApplyReport/oldman/Archives/index.vue'
// import ElderArchives from '@/views/datacenter/basicData/oldman/components/Archives/index.vue'
import apiMod from '@/apiMod'
import { filterEmptyObj } from '@/utils/util'
import CheckSelect from '@/views/instOperate/components/ApplyReport/components/CheckSelect/index.vue'

type Props = {
	params?: any
	creditCode?: string | number
	editData?: any
	isDetail?: boolean
	caseId?: string | number
	custome?: boolean
	approvalStatus?: string | number
	otherData?:any
	diffOrgArea?:boolean
	editMode?:any
	isOkApproval?:boolean
}
const props = withDefaults(defineProps<Props>(),{
	editMode:{
		crAreaSame:false,
		orgCrArea:false,
		societyAudit:false,
		elderCrArea:false,
		streetAudit:false,
		assessOrgAudit:false,
		civilAudit:false,
		isOkApproval:false
	}
})

const emit = defineEmits(['save'])
let tableLoad = ref(true)
const detailConfig = {
	customeHeader: {
		integrityConfig: {
			baseTableName: 'dp_service_object',
			materialTableName: 'dp_service_object_material',
			soleValue: 'idCard',
		},
		type: 'CardTwo',
		title: 'oldmanName',
		avatar: 'image',
		tipList: [{ prop: 'oldmanPhone', type: 'tip-success', label: '联系电话' }],
		tagList: [
			{
				prop: 'countryLevel',
				propName: 'countryLevelLabel',
				code: 'ACCESS_LEVEL_COUNTRY',
				custome: 'tag',
				type: 'success',
				label: '能力等级',
			},
			{ prop: 'birthday', type: 'success', label: '公历' },
			{ prop: 'lunarBirthday', type: 'success', label: '农历' },
		]
	},
}
let archivalShow = ref(false)
const model = ref({
	year: '',
	month: '',
})
let dict1 = [
	{label:'属实',value:1},
	{label:'不属实',value:2},
]
let dict2 = [
	{label:'能够完全自理',value:1},
	{label:'不能够完全自理',value:2},
]
let dict3 = [
	{label:'自理',value:1},
	{label:'半失能',value:2},
	{label:'失能',value:3},
	{label:'失智',value:4}
]
let dict4 = [
	{label:'无异议',value:1},
	{label:'有异议',value:2}
]
let dict5 = reactive([
	{label:'死亡',value:1},
	{label:'户口从本市迁出',value:2},
	{label:'被取消低保待遇',value:3},
	{label:'与养老机构服务合同终止',value:4},
	{label:'补助资格逾期未入住养老机构',value:5},
	{label:'其他,情况是：__________',value:6}
])

const drawer = ref(false)
const baseModel: any = shallowRef({})
const loading = ref(false)
const modelData: any = ref({
	reflectSituation:0
})
const orgArchivesEl = ref(null)
let moreNewsModel: any = ref({
	organizationInfoPO: {},
})


const tableColumnConfig = (data?: any) => {
	return [
		[
			{ m: '申请人姓名',style:{width:'200px'} },
			{
				m: '',
				prop: 'oldmanName',
				archives: true,
				archivesText: '档案',
				setColor: true,
				showLink: (col, model) => {
					archivalShow.value = true
				},
			},
			{ m: '性别', style: { width: '180px' } },
			{
				m: '',
				setColor: true,
				prop: 'genderLabel',
			},
			{
				m: '照片',
				mc: {
					rs: 4,
					cs: 1,
				},
				prop:"oldmanImage",
			},
		],
		[
			{ m: '民族' },
			{
				m: '',
				prop: 'nationalityLabel',
				setColor: true,
			},
			{ m: '身份证号' },
			{
				m: '',
				setColor: true,
				prop: 'idCard',
			},
		],
		[
			{ m: '户口所在地' },
			{
				m: '',
				setColor: true,
				prop: 'crDetail',
			},
			{ m: '联系电话' },
			{
				m: '',
				prop: 'oldmanPhone',
				setColor: true,
			},
		],
		[
			{ m: '现家庭住址' },
			{
				m: '',
				prop: 'addressDetail',
				setColor: true,
				mc: {
					rs: 1,
					cs: 3,
				},
			},
		],
		[
			{
				m: '入住机构与老年人户籍所在地不在同一个区填写',
			},
			{
				m: '',
				prop: 'areaOpinion',
				mc: {
					rs: 1,
					cs: 2,
				},
			},
			{
				m: '',
				prop: 'crAreaOpinion',
				mc: {
					rs: 1,
					cs: 2,
				},
			},
		],
		[
			{m:'街道（镇）初审情况'},
			{
				m: '',
				prop: 'TrialOutcome',
				mc: {
					rs: 1,
					cs: 4,
				},
			},
		],
		[
			{m:'社会评估机构评估结论'},
			{
				m: '',
				prop: 'assessOutcome',
				mc: {
					rs: 1,
					cs: 4,
				},
			},
		],
		[
			{m:'社会公示情况'},
			{
				m: '',
				prop: 'publicityOutcome',
				mc: {
					rs: 1,
					cs: 4,
				},
			},
		],
		[
			{m:'区民政部门核准意见'},
			{
				m: '',
				prop: 'approvedOutcome',
				mc: {
					rs: 1,
					cs: 4,
				},
			},
		],
		[
			{m:'备注'},
			{
				m: '',
				prop: 'remark',
				mc: {
					rs: 1,
					cs: 4,
				},
			},
		],
	]
}
const dataList = ref(tableColumnConfig())

//修改勾选
const editCheck = (key,val) =>{
	modelData.value[key] = val
} 
// 设置领取时间
const editReceiveTime = () =>{

}

let editId = ref('')
let hideInput = ref(false)
const getInitData = async () => {
	if(props.otherData&&props.otherData.approvalStatus&&props.otherData.approvalStatus==1&&props.editData){
		console.log('1')
		modelData.value = props.otherData.ofsSubsidyApplyElderlyPO
		baseModel.value = props.otherData.ofsSubsidyApplyElderlyPO
		if(modelData.value.stopAidOtherReason){
			dict5[5].label = '其他,情况是:'+'<span style="text-decoration: underline;text-underline-offset:3px;font-weight: bold;">'+modelData.value.stopAidOtherReason+'</span>'
		}
		tableLoad.value = false
		return
	}else if(props.params&&props.params.id){
		console.log('2')
		if(props.caseId){
			editId.value = props.caseId
			modelData.value = props.editData
			baseModel.value = props.editData
			if(modelData.value.stopAidOtherReason){
				dict5[5].label = '其他,情况是:'+'<span style="text-decoration: underline;text-underline-offset:3px;font-weight: bold;">'+modelData.value.stopAidOtherReason+'</span>'
			}
			tableLoad.value = false
		}else{
			let date = [undefined,undefined]
			if(props.params.belongDate){
				date = props.params.belongDate.split("-")
			}
			let result = props.params.tableRel?JSON.parse(props.params.tableRel):[]
			let query = {
				applyMonth:date[1],
				applyYear:date[0],
				formId:props.params.applyNo,
				formType:'PK_elder_stay_report',
				id:result[0]?.result,
				tableTemplateId:'PK_elder_stay_report'
			}
			let res = await apiMod.view_formResults_list(query)
			if(res.code==0&&res.data[0]){
				editId.value = res.data[0].id
				modelData.value = res.data[0].dataContent
				baseModel.value = res.data[0].dataContent
				if(modelData.value.stopAidOtherReason){
				dict5[5].label = '其他,情况是:'+'<span style="text-decoration: underline;text-underline-offset:3px;font-weight: bold;">'+modelData.value.stopAidOtherReason+'</span>'
			}
			tableLoad.value = false
			}
		}
	}else{
		// 归档
		console.log('3')
		modelData.value = props.editData
		baseModel.value = props.editData
		hideInput.value = true
		tableLoad.value = false
	}
}
 // 保存编辑数据
 const saveEditData = () =>{
	let query = {
		id:editId.value,
		dataContent: modelData.value,
		dataResults: modelData.value,
		fromId: props.otherData.applyNo,
		fromType: 'PK_elder_stay_report',
		tableTemplateId: 'PK_elder_stay_report',
		projectId:props.otherData.subsidyProjectId,
	}
	apiMod.view_formResults_edit(query).then(res=>{
		ElMessage.success('修改成功')
	})
 }
 // 编辑所有数据
 const editAllData = async() =>{
	await apiMod.view_ofsSubsidyApplyElderly_edit({
			...props.otherData.ofsSubsidyApplyElderlyPO,assessAbilityLevel:modelData.value.assessAbilityLevel,
			startSubsidyDate:modelData.value.startSubsidyDate
		})
	saveEditData()
 }
onMounted(() => {
	getInitData()
})

const handleSave = () => {
	emit('save', modelData.value, 'PK_elder_stay_report', props.editData)
}

onUnmounted(() => {})
</script>

<style scoped lang="scss">
.left_right {
	margin: 20px 0;
	width: 90%;
	display: flex;
	flex-direction: row;
	justify-content: space-between;
	align-items: center;
}
.report-table-wrapper {
	width: 100%;
	margin: 0 auto;
	padding: 10px 30px;
	top: 0;

	.t-header {
		text-align: center;
		font-size: 18px;
		font-weight: bold;
		padding: 15px 0;

		.text-sm {
			font-weight: 400;
			font-size: 16px;
		}
	}
}

.article-title {
	position: relative;
	z-index: 0;
	width: 63%;
	margin: 0 auto;
}

.text-tip {
	--base-text-bg: rgb(56 176 255 / 13%);
	position: absolute;
	width: 100%;
	height: 100%;
	background: var(--base-text-bg);
	padding: 4px;
	z-index: -1;
	&:hover {
		cursor: pointer;
	}
	.tip-text-new {
		position: absolute;
		right: 0;
		top: -10px;
		color: #fff;
		border-radius: 4px;
		padding: 2px;
		width: 40px;
		background-color: #ed6d05;
	}
	.tip-text-detail {
		background-color: #179fe3;
		position: absolute;
		right: 0;
		top: -10px;
		color: #fff;
		border-radius: 4px;
		padding: 2px;
		width: 40px;
	}
}
.add_underline{
	font-weight: bold;
	text-decoration: underline;
	text-underline-offset:3px;
}
.fr_sta{
	display: flex;
	flex-direction: row;
	justify-content: flex-start;
	align-items: center;
}
.input_part{
	display: inline-block;
	width: 200px;
}
</style>
